<template>
	<view class="container">
		<tui-tab :tabs="tabs" isSticky :current="currentTab" selectedColor="#E41F19" sliderBgColor="#E41F19"
			@change="change"></tui-tab>
		<view class="tui-records__list">
			<view class="itembox" v-for="(item,index) in datalist" :key="index">
				<tui-list-cell @click="getreportformsdetail(index)" :hover="false" unlined arrow>
					<view class="tui-records__item">
						<view>
							<view class="tui-title">{{ item.daytitle }}</view>
						</view>
						<view class="tui-right__box">
							<view class="tui-amount">
								+{{ item.daytotal }}
							</view>
						</view>
					</view>
				</tui-list-cell>
				<view class="itemdetailbox" v-if="item.detail.day">
					<view class="itemdetail">
						<view>
							<view class="tui-desc">现金收款 + {{item.detail.dayofflinetotal}}</view>
						</view>
						<view class="tui-right__box">
							<view class="tui-desc">共计 {{item.detail.dayofflineordercount}}笔</view>
						</view>
					</view>
					<view class="itemdetail">
						<view>
							<view class="tui-desc">平台结算 + {{item.detail.StoreIncome}}</view>
						</view>
						<view class="tui-right__box">
							<view class="tui-desc">共计 {{item.detail.StoreIncomecount}}笔</view>
						</view>
					</view>
					<view class="itemdetail">
						<view>
							<view class="tui-desc">购物卡核销金额 + {{item.detail.daygoodsgiftcardtotal}}</view>
						</view>
						<view class="tui-right__box">
							<view class="tui-desc">共计 {{item.detail.daygoodsgiftcardordercount}}笔</view>
						</view>
					</view>
					<view v-if="item.detail.category.length>0">
						<view  v-for="(cateitem,cateindex) in item.detail.category" :key="cateindex" class="itemdetail">
							<view>
								<view class="tui-desc">{{cateitem.title}} + {{cateitem.daytotal}}</view>
							</view>
							<view class="tui-right__box">
								<view class="tui-desc">共计 {{cateitem.dayordercount}}笔；{{cateitem.piece}}件</view>
							</view>
						</view>
					</view>
					<view class="itemdetail">
						<view>
							<view class="tui-desc">退款金额 + {{item.detail.dayreturnOrdertotal}}</view>
						</view>
						<view class="tui-right__box">
							<view class="tui-desc">共计 {{item.detail.dayreturnOrdercount}}笔</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: ["近7天", "本月", "上月"],
				currentTab: 0,
				datalist: []
			}
		},
		onLoad() {
			this.getRecordsList()
		},
		methods: {
			change(e) {
				this.currentTab = e.index;
				this.getRecordsList();
			},
			getRecordsList() {
				const _this = this
				_this.$request.post('adminstore.reportforms', {
					daytype: this.currentTab,
					page: 1
				}).then(res => {
					if (res.errno == 0) {
						_this.datalist = res.data
					} else {
						_this.datalist = []
					}
				})
			},
			getreportformsdetail(e) {
				const _this = this
				const day = _this.datalist[e].daytitle;
				_this.$request.post('adminstore.reportformsdetail', {
					day: day
				}).then(res => {
					if (res.errno == 0) {
						_this.datalist[e].detail = res.data
					}
				})
			}
		},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 200);
		},
		onReachBottom() {}
	}
</script>

<style>
	.container {
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-records__list {
		padding: 30rpx;
	}

	.itembox {
		background-color: #fff;
		border-radius: 20rpx;
		overflow: hidden;
		margin-bottom: 20rpx;
	}

	.tui-records__item {
		width: 100%;
		display: flex;
		align-items: center;
	}

	.itemdetailbox {
		padding-left: 35rpx;
		padding-right: 35rpx;
		padding-bottom: 30rpx;
	}

	.itemdetail {
		display: flex;
	}

	.tui-icon {
		width: 72rpx;
		height: 72rpx;
		margin-right: 20rpx;
	}

	.tui-title {
		font-size: 28rpx;
		font-weight: bold;
		color: #333333;
	}

	.tui-desc {
		font-size: 24rpx;
		font-weight: 400;
		color: #888888;
		padding-top: 12rpx;
	}

	.tui-right__box {
		margin-left: auto;
		text-align: right;
	}

	.tui-amount {
		padding-right: 28rpx;
		font-size: 28rpx;
		font-weight: bold;
	}

	.tui-expend {
		color: #19be6b !important;
	}
</style>